﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SIOCUR.Controllers;
using SIOCUR.Models;

namespace SIOCUR.Controllers
{
    public class InterfaseLoteController : Controller
    {
        SIOCURRepository dbpRepository = new SIOCURRepository();
        //
        // GET: /InterfaseLote/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Registra()
        {
            return View("Registra");
        }

        [HttpPost]
        public ActionResult Registra(FormCollection formValues, INTERFASE_DE_LOTES intflo)
        {
            String estacion = Session["sesionestacion"] as string;
            String sistema = Session["sesionsistema"] as string;

            if (ModelState.IsValid)
            {
                dbpRepository.AddInterfaseLote(estacion, sistema, DateTime.Now, Request.Form[0], Request.Form[1], Request.Form[2], Request.Form[3], Request.Form[4]);
                var interfaseLotes = dbpRepository.FindAllInterfaseLotes().ToList();
                return View("Agregado", interfaseLotes);
            }
            else
            {
                return View();
            }
            //return View();
        }

        public ActionResult Todos()
        {
            var interfaseLotes = dbpRepository.FindAllInterfaseLotes().ToList();
            return View(interfaseLotes);
        }

        public ActionResult Modifica()
        {
            String estacion = Session["sesionestacion"] as string;
            String sistema = Session["sesionsistema"] as string; 
            
            return View(dbpRepository.GetInterfaseLotes(estacion, sistema));
        }
        
        public ActionResult Modificar(int id)
        {
            INTERFASE_DE_LOTES il = dbpRepository.GetInterfaseLote(id);
            return View(il);

        }

        [HttpPost]
        public ActionResult Modificar(int id, FormCollection formValues)
        {
            INTERFASE_DE_LOTES il = dbpRepository.GetInterfaseLote(id);
            if (TryUpdateModel(il))
            {
                dbpRepository.Save();
                return RedirectToAction("Todos");
            }
            return View("Todos");
        }
           

    }
}
